<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="<%=path %>/js/bootstrap/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="<%=path %>/js/bootstrap/css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="<%=path %>/js/bootstrap/css/style.css" />

    <script type="text/javascript" src="<%=path %>/js/jquery.1.7.2.js"></script>
    <script type="text/javascript" src="<%=path %>/js/jQuery.FillOptions.js"></script>
    <script type="text/javascript" src="<%=path %>/js/jQuery.CascadingSelect.js"></script>
    <script type="text/javascript" src="<%=path %>/js/jquery.sorted.js"></script>
    <script type="text/javascript" src="<%=path %>/js/bootstrap/js/bootstrap.js"></script>
    <script type="text/javascript" src="<%=path %>/js/bootstrap/js/ckform.js"></script>
    <script type="text/javascript" src="<%=path %>/js/bootstrap/js/common.js"></script>
    <script>
	
	$(document).ready(
			function() {
				$("#finalParentNameList").FillOptions("<%=path %>/authority/getFinalParentName.do?",
			{
				datatype : "json",
				textfield :"name",
				valuefield :"id",
				keepold : false
			});
		$("#finalParentNameList").AddOption("顶级菜单", "0", true, 0);
		
		
		$("#finalParentNameList").val(${authority.parentId});
		
		jQuery("input[type='radio'][name='type'][value='${authority.type}']").attr("checked", "checked"); // 设置value = 2的一项为选中 
		
		jQuery("input[type='radio'][name='status'][value='${authority.status}']").attr("checked", "checked"); // 设置value = 2的一项为选中 
		
		$('#backid').click(function(){
			window.location.href="../authority/toMenuPage.do";
		 });
	});
	</script>
	<script>
	
	var mobileStatus = true;
	var nameStatus = true;
	function checkMobile(input) {
    	var mobile_number = input.value;
    	var urlreg=/^((https|http|ftp|rtsp|mms)?:\/\/)+[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/ 
    	
    	var tip = document.getElementById("urlTip");
    	if(!urlreg.test(mobile_number)){
    		alert("test");
    		$("#urlTip").append("请输正确的url地址!");
    		mobileStatus = false;
        	return false;        	
    	} else {
        	
    	}
	}
	
	function checkName(input) {
		var name_text = input.value;
		if(name_text.length>=10 || name_text.length<2) {
			nameTip.innerHTML = "请输入2个到10个之间的字符";
			nameStatus = false;
			return false;
		} else {

		}
	}
	
	function check(){
    	if (mobileStatus && nameStatus)    {
    		alert("呵呵, 编辑成功!");        
        	return true;    
        } else{
        	alert("格式不正确,请重新输入");        
        	return false;
        }
	}

	

    </script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
</head>
<body>
<form action="<%=path %>/authority/updateDo.do" method="post" class="definewidth m20"  onSubmit="return check();">
<input type="hidden" id="id" name="id" value="${authority.id}"/>
<table class="table table-bordered table-hover m10">
    <tr>
        <td width="10%" class="tableleft">父节点</td>
        <td>
            <select name="finalParentNameList" id="finalParentNameList" value="${authority.parentId}">
            </select>
            
        </td>
    </tr>
    <tr>
        <td class="tableleft">名称<font color='red'>*</font></td>
        <td><input type="text" name="name" onblur="checkName(this)" value="${authority.name}"/>
        	<span id="nameTip" style="color:red"></span>
        </td>
    </tr>
    <tr>
        <td class="tableleft">类型</td>
        <td>
            <input type="radio" id="type" name="type" value="按钮" checked/> 按钮
            <input type="radio" id="type" name="type" value="菜单"/> 菜单
        </td>
    </tr>
    <tr>
    	<td class="tableleft">url</td>
        <td><input type="text" name="url" onblur="checkMobile(this)" value="${authority.url}"/> <span id="urlTip" style="color:red"></span>
        </td>
    </tr>
    <tr>
        <td class="tableleft">状态</td>
        <td>
            <input type="radio" name="status" value="启用" checked/> 启用
            <input type="radio" name="status" value="禁用"/> 禁用
        </td>
    </tr>
    <tr>
        <td class="tableleft"></td>
        <td>
            <button type="submit" class="btn btn-primary" type="button">保存</button> &nbsp;&nbsp;<button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
        </td>
    </tr>
</table>
</form>
</body>
</html>